<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>打招呼录入</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-header"></div>
            <div class="layui-card-body">
                <div class="panel panel-default operation" hidden>
                    <div class="panel-heading title"></div>
                    <div class="layui-card-body">
                        <form class="layui-form " action="" lay-filter="info" style="width: 700px;margin-top: 10px">
                            <input name="id" hidden/>
                            <div class="layui-form-item">
                                <label class="layui-form-label">打招呼日期</label>
                                <div class="layui-input-block">
                                    <input type="greetDate" id="greetDate" name="greetDate" placeholder="请输入打招呼日期"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>


                            <div class="layui-form-item">
                                <label class="layui-form-label">打招呼人</label>
                                <div class="layui-input-block">
                                    <input type="greetMan" name="greetMan" placeholder="请输入打招呼人" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">打招呼单位</label>
                                <div class="layui-input-block">
                                    <input type="greetOrg" name="greetOrg" placeholder="打招呼单位" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">打招呼相关案件</label>
                                <div class="layui-input-block">
                                    <input type="greetFile" name="greetFile" placeholder="请输入打招呼相关案件" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">打招呼相关内容</label>
                                <div class="layui-input-block">
                                    <input type="greetConcent" name="greetConcent" placeholder="请输入打招呼相关内容"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
                                    <button class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>

                <div class="table_div">
                    <table class="layui-table" id="showTable" lay-filter="showTable"></table>
                </div>

            </div>
        </div>
    </div>
</div>

<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
    </div>
</script>
<script type="text/html" id="tool">
</script>

</body>
</html>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script th:inline="none">
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var tableIns1;
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    var greetDate = null;

    layui.use(['table', 'layer', 'laydate'], function () {


        laydate.render({
            elem: '#greetDate'
            , type: 'datetime'
            , done: function (value, date, endDate) {
                if (value != null && value != undefined && value != "") {
                    contentdate = value.split("~")[0];
                } else {
                    //清空时间的时候要清空以前选择的日期
                    greetDate = null;
                }
            }
        });


        //加载table
        tableIns1 = table.render({
            elem: '#showTable'
            , contentType: 'application/json'
            , headers: {"authorization": token}
            , page: true //开启分页
            , url: '/workflow/greet/list' //数据接口
            , method: 'POST'
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                }
            }
            , cols: [
                [
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'id', title: '${column.comments}', sort: true, hide: true},
                    {field: 'greetMan', title: '打招呼人', sort: true},
                    {field: 'greetOrg', title: '打招呼单位', sort: true},
                    {field: 'greetFile', title: '打招呼相关案件', sort: true},
                    {field: 'greetDate', title: '打招呼日期', sort: true},
                    {field: 'greetConcent', title: '打招呼相关内容', sort: true},
                ]
            ]
            , toolbar: '#toolbar'
        });


        //表头工具
        table.on('toolbar(showTable)', function (obj) {
            switch (obj.event) {
                case 'batchDeleted':
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data;
                    if (data.length == 0) {
                        layer.msg("请选择要批量删除的列");
                    } else {
                        var ids = [];
                        $(data).each(function (index, item) {
                            ids.push(item.id);
                        });
                        tipDialog(ids);
                    }
                    break;
                case 'add':
                    $(".table_div").hide();
                    $(".operation").show();
                    $(".title").html("新增");
                    $(".operation input[name=id]").val("");
                    $(".operation input[name=greetMan]").val("");
                    $(".operation input[name=greetOrg]").val("");
                    $(".operation input[name=greetFile]").val("");
                    $(".operation input[name=greetDate]").val("");
                    $(".operation input[name=greetConcent]").val("");
                    $(".operation input[name=field1]").val("");
                    $(".operation input[name=field2]").val("");
                    $(".operation input[name=field3]").val("");
                    $(".operation input[name=taxorgcode]").val("");
                    $(".operation input[name=deleted]").val("");
                    $(".operation input[name=createTime]").val("");
                    $(".operation input[name=updateTime]").val("");
                    $(".operation input[name=createId]").val("");
                    $(".operation input[name=updateId]").val("");
                    break;
            }
            ;
        });

        //列操作
        table.on('tool(showTable)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'del':
                    var ids = [];
                    ids.push(data.id);
                    tipDialog(ids);
                    break;
                case 'edit':
                    $(".table_div").hide();
                    $(".operation").show();
                    $(".title").html("编辑");
                    $(".operation input[name=id]").val(data.id);
                    $(".operation input[name=greetMan]").val(data.greetMan);
                    $(".operation input[name=greetOrg]").val(data.greetOrg);
                    $(".operation input[name=greetFile]").val(data.greetFile);
                    $(".operation input[name=greetDate]").val(data.greetDate);
                    $(".operation input[name=greetConcent]").val(data.greetConcent);
                    $(".operation input[name=field1]").val(data.field1);
                    $(".operation input[name=field2]").val(data.field2);
                    $(".operation input[name=field3]").val(data.field3);
                    $(".operation input[name=taxorgcode]").val(data.taxorgcode);
                    $(".operation input[name=deleted]").val(data.deleted);
                    $(".operation input[name=createTime]").val(data.createTime);
                    $(".operation input[name=updateTime]").val(data.updateTime);
                    $(".operation input[name=createId]").val(data.createId);
                    $(".operation input[name=updateId]").val(data.updateId);
                    break;
            }
        });

        //返回
        $("#btn_cancel").click(function () {
            $(".table_div").show();
            $(".operation").hide();
            return false;
        });

        //监听保存
        form.on('submit(submit)', function (data) {
            if (data.field.id === undefined || data.field.id === null || data.field.id === "") {
                CoreUtil.sendPost("/workflow/greet/write", data.field, function (res) {
                    $(".table_div").show();
                    $(".operation").hide();
                    search();
                });
            }
            return false;
        });
    });

    //执行查询
    function search() {
        //这里以搜索为例
        tableIns1.reload({
            where: { //设定异步数据接口的额外参数，任意设
                key: $("#key").val()
            }
            , page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    };
</script>